package cn.itcast.mapper;

import cn.itcast.dao.Company;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface CompanyMapper {
    @Select("select * from st_company")
    List<Company> findAll();

    @Update("update st_company set name = #{name,jdbcType=VARCHAR},\n" +
            "        expiration_date = #{expiration_date,jdbcType=TIMESTAMP},\n" +
            "        address = #{address,jdbcType=VARCHAR},\n" +
            "        license_id = #{license_id,jdbcType=VARCHAR},\n" +
            "        representative = #{representative,jdbcType=VARCHAR},\n" +
            "        phone = #{phone,jdbcType=VARCHAR},\n" +
            "        company_size = #{company_size,jdbcType=VARCHAR},\n" +
            "        industry = #{industry,jdbcType=VARCHAR},\n" +
            "        remarks = #{remarks,jdbcType=VARCHAR},\n" +
            "        state = #{state,jdbcType=INTEGER},\n" +
            "        city = #{city,jdbcType=VARCHAR}\n" +
            "        where id = #{id,jdbcType=VARCHAR}")
    void edit(Company company);

    @Select("select * from st_company where id=#{id}")
    Company toEdit(String id);

    @Insert("insert into st_company (id, name, expiration_date,\n" +
            "        address, license_id, representative,\n" +
            "        phone, company_size, industry,\n" +
            "        remarks, state,\n" +
            "        city)\n" +
            "        values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{expiration_date,jdbcType=TIMESTAMP},\n" +
            "        #{address,jdbcType=VARCHAR}, #{license_id,jdbcType=VARCHAR}, #{representative,jdbcType=VARCHAR},\n" +
            "        #{phone,jdbcType=VARCHAR}, #{company_size,jdbcType=VARCHAR}, #{industry,jdbcType=VARCHAR},\n" +
            "        #{remarks,jdbcType=VARCHAR}, #{state,jdbcType=INTEGER},\n" +
            "        #{city,jdbcType=VARCHAR})")
    void save(Company company);

    @Delete("delete from st_company where id = #{id}")
    void deleteById(String id);
}
